﻿using System;
using System.Collections.Generic;
using System.Data;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using VideoNetApplication.Common; 
using VideoNetApplication.Common.Helper;
using VideoNetApplication.Common.Service;
using System.Text;

namespace VideoNetApplication
{
    public partial class _Default : BasePage
    {
       
        public string SchoolImg = string.Empty;
        protected void Page_Load(object sender, EventArgs e)
        {
            
            SchoolNews();
            ShowRecruits();
            ShowTeachers();
            ShowSchoolInfo(); 

        }
        /// <summary>
        /// 学校简介
        /// </summary>
        public  void  ShowSchoolInfo()
        {
            var s = new SchoolConfigService();
            V_school school =s.QuerySchoolById(SchoolId) ;
            if (school != null)
            {
                SchoolImg = string.IsNullOrEmpty(school.VS_schoolImg)
                                ? "Images/nopic.gif"
                                : PictureServerName + school.VS_schoolImg;
                ltrInfo.Text = StringUtils.getLimitLengthString(school.VS_Desc, 400, "...");
            }


        }

        /// <summary>
        /// 学校新闻
        /// </summary>
        private void SchoolNews()
        {
            var newsService = new NewsService();
            int outcount=0;
            List<V_News> vNewses = newsService.GetNewsList(SchoolId, 1, 4, out outcount);
            StringBuilder buffer=new StringBuilder();
            for (int i = 0; i < vNewses.Count; i++)
            {
                if (i==0)
                {
                    buffer.AppendFormat("<div class=\"news_hun\"><a class=\"pic\" href=\"ViewNewsDetail.aspx?nid={0}&schoolID={1}\"><img src=\"{2}\" /></a><h4><a href=\"ViewNewsDetail.aspx?nid={0}&schoolID={1}\">{3}</a></h4><p>{4}</p></div><ul class=\"news_list\">", vNewses[i].ID, SchoolId, string.IsNullOrEmpty(vNewses[i].NewsImage) ? "Images/3.JPG" : PictureServerName+ vNewses[i].NewsImage, StringUtils.getLimitLengthString(vNewses[i].NewsTitle, 40, ""), StringUtils.getLimitLengthString(StringUtils.DropHtmlTag(vNewses[i].NewsContent), 100, "..."));
                }else
                {
                    buffer.AppendFormat("<li><a href=\"ViewNewsDetail.aspx?nid={0}&schoolID={1}\">{2}</a>&nbsp;&nbsp;&nbsp;&nbsp;{3}</li>", vNewses[i].ID, SchoolId, StringUtils.getLimitLengthString(vNewses[i].NewsTitle, 40, ""), DateTime.Parse(vNewses[i].CreatedTime.ToString()).ToString("yyyy-MM-dd"));

                }
            }
            buffer.Append("</ul>");
            ltrNews.Text = buffer.ToString();
        }
        /// <summary>
        /// 招生简章
        /// </summary>
        private void ShowRecruits()
        {
            RecruitStudentService recruitStudentService = new RecruitStudentService();
            int recordcount = 0;
            List<V_RecruitStudent> vRecruitStudents = recruitStudentService.GetRecruitList(SchoolId,1,6,out recordcount);
            repRecruit.DataSource = vRecruitStudents;
            repRecruit.DataBind();

        }
        //教师简介
        private void ShowTeachers()
        {
            TeacherService teacherService=new TeacherService();
            int outCout=0;
            List<V_teacher> vTeachers = teacherService.GetTeacherByALL(SchoolId, 1, 3,out outCout);
            repTeacher.DataSource = vTeachers;
            repTeacher.DataBind();
        }

      
    }
}
